package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DeleteOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("输入书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = bookList.getUsedSize();
        int index = -1;
        for (int i = 0; i < size; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)==true) {
                index = i;
                break;
            }
        }
        if(index == -1){
            System.out.println("没有你要删的书");
        }
        for (int i = index; i < size-1; i++) {
            Book book = bookList.getBooks(i+1);
            bookList.setBooks(i,book);
        }
        bookList.setUsedSize(size-1);
        System.out.println("删除成功");
    }
}
